package com.zh.search.dataSource;

import com.zh.web.enums.SearchType;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

@Component
public class DataSourceRegistry {

    private final ArticleEsDataSource articleDataSource;
    private final VideoEsDataSource videoDataSource;

    private final Map<SearchType, EsDataSource<?>> typeDataSourceMap = new HashMap<>();

    DataSourceRegistry(ArticleEsDataSource articleDataSource, VideoEsDataSource videoDataSource) {
        this.articleDataSource = articleDataSource;
        this.videoDataSource = videoDataSource;
    }

    @PostConstruct
    public void init() {
        typeDataSourceMap.put(SearchType.ARTICLE, articleDataSource);
        typeDataSourceMap.put(SearchType.VIDEO, videoDataSource);
    }

    public EsDataSource<?> getDataSourceByType(SearchType searchType) {
        return typeDataSourceMap.get(searchType);
    }
}
